/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OpretProdukt.java
 *
 * Created on Nov 22, 2011, 8:21:44 PM
 */
package GUILayer;
import ControlLayer.CtrProduct;
import ModelLayer.Product;
import ControlLayer.CtrSupplier;
import ModelLayer.Supplier;
/**
 *
 * @author R3l4X
 */
public class OpretProdukt extends javax.swing.JFrame {
    private CtrProduct ctrProduct;
    private CtrSupplier ctrSupplier;
    /** Creates new form OpretProdukt */
    public OpretProdukt() {
        initComponents();
         this.setVisible(true);
            lblLeverandørID.setEnabled(false);
            txtProduktOpretLeverandorID.setEnabled(false);
            txtProduktOpretLeverandorID.setText("0");
            
         
          ctrProduct = new CtrProduct();
          ctrSupplier = new CtrSupplier();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        btnProduktOpretCancel = new javax.swing.JButton();
        btnProduktOpretOpret = new javax.swing.JButton();
        txtProduktOpretLeverandorID = new javax.swing.JTextField();
        txtProduktOpretAntalLager = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        txtProduktOpretMax = new javax.swing.JTextField();
        txtProduktOpretMin = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        txtProduktOpretPlacering = new javax.swing.JTextField();
        txtProduktOpretPris = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        txtProduktOpretDimensioner = new javax.swing.JTextField();
        txtProduktOpretType = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        lblOpretProdukt = new javax.swing.JLabel();
        lblLeverandør = new javax.swing.JLabel();
        chkLeverandor = new javax.swing.JCheckBox();
        lblLeverandørID = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Opret Produkt");

        btnProduktOpretCancel.setText("Annuller");
        btnProduktOpretCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProduktOpretCancelActionPerformed(evt);
            }
        });

        btnProduktOpretOpret.setText("Opret");
        btnProduktOpretOpret.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProduktOpretOpretActionPerformed(evt);
            }
        });

        jLabel9.setText("Antal På Lager");

        jLabel10.setText("Maximum");

        jLabel8.setText("Minimum");

        jLabel7.setText("Placering");

        jLabel4.setText("Pris");

        jLabel5.setText("Dimensioner");

        jLabel3.setText("Type");

        lblLeverandør.setText("Leverandør");

        buttonGroup1.add(chkLeverandor);
        chkLeverandor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                chkLeverandorActionPerformed(evt);
            }
        });

        lblLeverandørID.setText("Leverandør ID");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(btnProduktOpretOpret)
                        .addGap(18, 18, 18)
                        .addComponent(btnProduktOpretCancel))
                    .addComponent(lblOpretProdukt)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel5)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jLabel7)
                                    .addComponent(jLabel8)))
                            .addComponent(jLabel4)
                            .addComponent(jLabel10)
                            .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel9)
                            .addComponent(lblLeverandørID)
                            .addComponent(lblLeverandør))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chkLeverandor)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addComponent(txtProduktOpretType, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                                    .addComponent(txtProduktOpretPlacering)
                                    .addComponent(txtProduktOpretAntalLager)
                                    .addComponent(txtProduktOpretMax)
                                    .addComponent(txtProduktOpretMin, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtProduktOpretDimensioner, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(txtProduktOpretPris, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addComponent(txtProduktOpretLeverandorID, javax.swing.GroupLayout.DEFAULT_SIZE, 133, Short.MAX_VALUE)))))
                .addContainerGap(169, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProduktOpretType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProduktOpretDimensioner, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProduktOpretPris, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProduktOpretPlacering, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(txtProduktOpretMin, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProduktOpretMax, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtProduktOpretAntalLager, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(78, 78, 78)
                        .addComponent(lblOpretProdukt))
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(chkLeverandor)
                            .addComponent(lblLeverandør))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtProduktOpretLeverandorID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(lblLeverandørID))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnProduktOpretOpret)
                    .addComponent(btnProduktOpretCancel))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void btnProduktOpretOpretActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProduktOpretOpretActionPerformed

    opretProdukt();
}//GEN-LAST:event_btnProduktOpretOpretActionPerformed

    private void btnProduktOpretCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProduktOpretCancelActionPerformed

        setVisible(false);
        // TODO add your handling code here:
    }//GEN-LAST:event_btnProduktOpretCancelActionPerformed

    private void chkLeverandorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_chkLeverandorActionPerformed

               
        if(chkLeverandor.isEnabled())
        {
            lblLeverandørID.setEnabled(true);
            txtProduktOpretLeverandorID.setEnabled(true);
            
        }

    }//GEN-LAST:event_chkLeverandorActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(OpretProdukt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(OpretProdukt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(OpretProdukt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(OpretProdukt.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new OpretProdukt().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnProduktOpretCancel;
    private javax.swing.JButton btnProduktOpretOpret;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JCheckBox chkLeverandor;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel lblLeverandør;
    private javax.swing.JLabel lblLeverandørID;
    private javax.swing.JLabel lblOpretProdukt;
    private javax.swing.JTextField txtProduktOpretAntalLager;
    private javax.swing.JTextField txtProduktOpretDimensioner;
    private javax.swing.JTextField txtProduktOpretLeverandorID;
    private javax.swing.JTextField txtProduktOpretMax;
    private javax.swing.JTextField txtProduktOpretMin;
    private javax.swing.JTextField txtProduktOpretPlacering;
    private javax.swing.JTextField txtProduktOpretPris;
    private javax.swing.JTextField txtProduktOpretType;
    // End of variables declaration//GEN-END:variables

   private Supplier supp;
   
   private void opretProdukt()
   {
       CtrProduct ctrProd = new CtrProduct();
        CtrSupplier ctrSup = new CtrSupplier();
      
        Supplier supObj = new Supplier();
        Product prodObj = new Product();
        
        prodObj.setType(txtProduktOpretType.getText());
        prodObj.setDimensions(Double.valueOf(txtProduktOpretDimensioner.getText()));
        prodObj.setPrice(Double.valueOf(txtProduktOpretPris.getText()));
        prodObj.setPlacement(txtProduktOpretPlacering.getText());
        prodObj.setMinStock(Integer.valueOf(txtProduktOpretMin.getText()));
        prodObj.setMaxStock(Integer.valueOf(txtProduktOpretMax.getText()));
        prodObj.setCurrentStock(Integer.valueOf(txtProduktOpretAntalLager.getText()));
        
        supObj.setSupID(Integer.parseInt(txtProduktOpretLeverandorID.getText()));
        
        prodObj.setSupplierID(supObj);
        
        System.out.println(supObj.getSupID());        
        ctrProd.insertProduct(prodObj);
        
        
        lblOpretProdukt.setText("Produktet er Oprettet med følgende ID : " + ctrProd.getMaxID());
   }
}
